# Set MX records at ISP

# 1.Install prerequisite
# only mailx can you using "mail" command rather than "/usr/sbin/sendmail"
yum install m4 telnet mailx

# 2.check if sendmail is installed or not
rpm –qa | grep sendmail

# 3. if not
yum install sendmail sendmail-cf

# By default sendmail configuration files are located at /etc/mail.
# By default sendmail listen on local interface i.e 127.0.0.1, check using this command:
# You can examine it
ps -ef | grep -v grep | grep -i sendmail
netstat -an | grep :25 | grep tcp

# To configure the sendmail to listen to all 
# interface at the host, just comment the following line in “sendmail.mc”:
vim /etc/mail/sendmail.mc
# From:
# DAEMON_OPTIONS(`Port=smtp,Addr=127.0.0.1, Name=MTA')dnl
# To
# dnl DAEMON_OPTIONS(`Port=smtp,Addr=127.0.0.1, Name=MTA')dnl

# OR
# DAEMON_OPTIONS(`Port=smtp, Addr=127.0.0.1 Name=MTA’)dnl
# to
# DAEMON_OPTIONS(`Port=smtp, Name=MTA’)dnl


vim /etc/mail/sendmail.mc
# replace mail.miyisp.com to real address
# define(`SMART_HOST',`mail.myisp.com')dnl



# Now we need to build the “sendmail.cf” file using m4 macro:
m4 /etc/mail/sendmail.mc > /etc/mail/sendmail.cf


# Restart Sendmail Service:
service sendmail restart


# Check using this command:
netstat -an | grep :25 | grep tcp


# a) Adding your domain entry in “/etc/mail/local-host-names” file:
vim /etc/mail/local-host-names
# 添加以下域名到主机名
# xyz.com
# xyz.co.in


# b)modifiy
vim /etc/sysconfig/network


# 改hostname有时只能通过控制面板改，临时改动可以通过hostname object.domain来改动。
# c) /etc/hosts
# 127.0.0.1 localhost.localdomain localhost localhost4.localdomain4 localhost4
# # Auto-generated hostname. Please do not remove this comment.
# 185.122.57.56 mail.xingtingyang.cn  mail
# ::1         localhost localhost.localdomain localhost6 localhost6.localdomain6


# d) very import and don't use vim to change hostname
# echo xingtingyang.cn >  /proc/sys/kernel/hostname



service sendmail restart
chkconfig sendmail on


# 使用mail命令编辑邮件和发送邮件
# mail -s "Test mail from testuser1" testuser2
# Hello this is the test mail
# .
# EOT
# 停止编辑右键，自动生成EOT using CTRL+D


# 成功的交易日志
tail /var/log/maillog


# 交易简略，需要安装mailx
mail

# 详细的交易记录，包括邮件内容
cat /var/spool/mail/root


# iptables
iptables -A INPUT -p tcp -m tcp –dport 25 -j ACCEPT
service iptables save
service iptables restart


# PHP send mail
php -r'mail("user@somedomain.com", "Subject", "Body", null, "-fme@mydomain.com");'
# or skip from address
php -r'mail("user@somedomain.com", "Subject", "Body");'
# in which case the sender's name become automatically user@hostname, eg. 

# 重启电脑
reboot